Design patterns are used in software design to enhance the quality and robustness of software applications. Design patterns are arrangements of classes and objects. An example of a design pattern is a Model View Controller (MVC) design pattern. A software application that includes classes organized as an MVC design pattern (an “MVC software application”) separates the user interface of the MVC software application from the core functionality of the MVC software application.
The separation of an MVC software application into a Model, a View, and a Controller enhances the quality and robustness of the MVC software application. Typically, each of the Model, the View, and the Controller is a collection of one or more objects and classes.
The Model manages the core functionality of the MVC software application. The View manages that portion of the MVC software application that is visible to a user on a computer display device, e.g., an area of the computer screen known as a graphical user interface (GUI). The Controller performs actions on the Model which may result in changes to the View, or performs actions on the View directly.
Each View has one associated Controller and each Controller has one associated View. In general, each Controller-View pair is associated with a single Model. However, the Model may be associated with many Controller-View pairs. For example, a block diagram shown in FIG. 1 illustrates a single Model (80) associated with two different Controller-View pairs (90, 92) where one View (82) presents data managed by the Model (80) as a table (86), and another View (82) presents the data as a chart (88).
As with most object-oriented models, the View, the Controller, and the Model communicate by sending messages among Model objects, View objects, and Controller objects. FIG. 2 illustrates an example of the flow of communication between the View, the Controller, and the Model using messages. In this example, a user inputs a change via an input device (100) to data (102) managed by a Model (80). As a result, a Controller (84) sends a first message (104) to the Model (80). Sending the first message (104) causes the data (102) managed by the Model (80) to change, triggering two second messages (106, 109) from the Model (80), notifying all View and Controller objects (107) that have registered as a listener of the change. As a result of the notification, data output to one or more GUI windows (108) may be updated by the affected View-Controller pairs (107), if needed. Subsequently, the View (82) and the Controller (84) as a pair, each send a third message (110, 111) to the Model (80) retrieving updated data and reflecting the changed data in the GUI windows (108) managed by the View (82).
Messages sent among Model objects, View objects, and Controller objects may be implemented via multiple techniques. For example, a View object may send a message in order to obtain a value of a field of a Model object by invoking a method of the Model object, such as the following: statusValue=modelObjectA.getStatus( ).
Those skilled in the art will realize that allowing the View object to access the getStatus( ) method of modelObjectA may be accomplished through multiple techniques, e.g., setting an access protection level for the getStatus( ) method appropriately.
Design patterns, such as the MVC design pattern, may be used to help manage data collected from users of MVC software applications. For example, an MVC software application may present a GUI to a user in order to collect data from the user. Input fields of the GUI (e.g., textboxes) receive data entered by the user. Certain input fields may be designated as receiving certain types of data. For example, an input field labeled as “Zip Code” may receive numeric data, an input field labeled “Name” may receive alphabetic data, and an input field labeled “Address” may receive alphanumeric data. However, due to human error or other causes, an input field occasionally receives data of a type other than what the input field is meant to receive. For example, the input field labeled “Zip Code” may accidentally receive alphabetic data.
Data validation is used by software applications, such as MVC software applications, in order to ensure that data entered into an input field is of a correct type, or is of a correct range, or possesses certain desired characteristics. In an MVC application, because core functionality is intrinsic to the Model, data validation is performed by the Model. In order to perform data validation of data entered into an input field, the Model contains data validation rules, which are usually expressed as programmed comparison statements. Data validation rules may extend to cover other aspects of data entry besides data type and value (e.g., ensuring that the “Zip Code” input field receives only numeric data, or that a number input into an input field falls between certain desired values). For example, a data validation rule may ensure that every input field on a GUI be completed by the user.
As an example of a typical data validation scenario with an MVC software application, a user may type the word “Joe” into the “Zip Code” input field. The Controller sends a first message to the Model containing the data entered by the user, i.e., “Joe.” A data validation rule associated with the “Zip Code” input field is accessed by the Model. Because the “Zip Code” field data validation rule requires that data entered into The “Zip Code” field be numeric data, the Model determines that “Joe” constitutes invalid data and takes appropriate action. For example, the Model may send a second message to the Controller indicating that “Joe” is invalid data for the “Zip Code” field. Subsequently, the Controller sends a third message to the View, causing the View to display a pop-up window visible to the user, containing text such as “Please Enter Numeric Data Only Into the Zip Code Field.”
The Model, View, and Controller of an MVC software application may exist on multiple computers. For example, in the foregoing data validation scenario, the View that created a GUI containing the input field labeled “Zip Code” may be embodied by a scripting language program executing on a web browser on a personal computer connected to the Internet and located in a first location. The Model and the Controller may be embodied by one or more high-level language programs executing on a server also connected to the Internet and located in a second location. Thus, the first message (sent from the View to the Model) and the third message (sent from the Controller to the View) travel round trip over the Internet connection from the first location to the second location, and back again.